//#include "StdAfx.h"
#include ".\myui_cimage.h"

myui_CImage::myui_CImage(void)
{
	autoSize = true;
	pic = NULL;
}

myui_CImage::~myui_CImage(void)
{
	if (pic)
		g_PicResManage.FreeBitmap(pic);
}

bool myui_CImage::Init(int x, int y, char* FileName)
{
	if (pic)
		g_PicResManage.FreeBitmap(pic);

	pic = g_PicResManage.CreateBitmapFromBMP(FileName);
	if (!pic)
		return false;

	return myui_CWinControl::Init(x, y, pic->GetWidth(), pic->GetHeight());
}

bool myui_CImage::LoadFormBmp(char* FileName)
{
	if (pic)
		g_PicResManage.FreeBitmap(pic);

	pic = g_PicResManage.CreateBitmapFromBMP(FileName);
	if (!pic)
		return false;
	if (autoSize)
	{
		if (m_image)
			GetGraphics()->RemoveBitmap(m_image);
		m_width = pic->GetWidth();
		m_height = pic->GetHeight();
		m_image = GetGraphics()->CreateBitmap(m_width, m_height);
		if (!m_image)
			return false;
	}
	return true;
}

bool myui_CImage::Draw(LP_BITMAPX image)
{
	if (!m_image)
		return false;
	if (!myui_CWinControl::Draw(m_image))
		return false;
	if (pic)
		GetGraphics()->DrawBitmap(0, 0, pic, m_image, true);
	GetGraphics()->DrawBitmap(getX(), getY(), m_image, image, true);
	return true;
}